/*
 * @Description: 按存储格式
 * @Author: Zzt
 * @Date: 2022-11-11 14:52:39
 * @LastEditTime: 2022-12-26 10:36:50
 */
import VisualizationMain from '@/components/DataVisualization/VisualizationMain';
import classNames from 'classnames/bind';
import { useEffect, useState } from 'react';
import { useFamilyStatisticsContext } from '../contexts/FamilyStatisticsContext';
import styles from '../styles/familyStatistics.module.scss';
const cx = classNames.bind(styles);

const table: any[] | (() => any[]) = [];

const StorageFormat = (props: any) => {
  const { ATList } = props;
  const { storageFormatList, setStorageFormat, storageList } = useFamilyStatisticsContext();
  const [changedValue, setChangeValue] = useState({});

  // 选中的按照类型
  const [visibleData, setVisibleData] = useState([]);
  const [condition, setCondition] = useState(<></>);
  const [tableList, setTableList] = useState(table);
  const [xData, setXData] = useState();
  const [yData, setYData] = useState([]);
  useEffect(() => {
    setStorageFormat(changedValue);
  }, [changedValue]);

  useEffect(() => {
    setVisibleData(storageFormatList);
    setYData(storageFormatList?.map((item: any) => item?.formatName));
    setXData(storageFormatList?.map((item: any) => item?.total));
    setCondition(<></>);
  }, [storageFormatList]);
  /* 改变触发 */
  const onChangeYear = (value: any) => {
    setChangeValue(value.chioce);
  };
  return (
    <>
      <h2 className={cx('title')}>按存储格式</h2>
      <VisualizationMain
        type={'时间'}
        condition={condition}
        segmented={[]}
        tableList={tableList}
        choiceList={[
          { title: '档案类型', name: 'archiveTypeIds', checkList: ATList },
          {
            title: '格式',
            name: 'formats',
            checkList: storageList
          }
        ]}
        data={{ visibleData, xData, yData }}
        onChange={onChangeYear}
      />
    </>
  );
};
export default StorageFormat;
